/*
 * Copyright (C) 2011, EADS France
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 */
package xowl.generator.proxy;

/**
 *
 * @author Laurent WOUTERS
 */
public class ActivatorWriter {
    public static void write(String folder, xowl.generator.ModelGenerator mg) throws java.io.IOException {
        java.io.Writer writer = xowl.utils.Files.getWriter(folder + "Activator.java");
        writer.append("/* This file has been generated by:\n");
        writer.append("   xOWL Code Generator\n");
        writer.append("*/\n");
        writer.append("package " + mg.getBasePackage() + ";\n");
        writer.append("\n");

        writer.append("public class Activator {\n");
        writer.append("    public static void activate() {\n");
        for (xowl.generator.PackageGenerator pack : mg.getPackages()) {
            if (pack instanceof xowl.generator.ReflectionPackage)
                continue;
            if (pack instanceof xowl.generator.ReferencePackage)
                continue;
            for (xowl.generator.ClassGenerator cg : pack.getClasses()) {
                if (!cg.isAbstract())
                    writer.append("        " + cg.getJavaName() + ".register();\n");
            }
            for (xowl.generator.ClassGenerator cg : pack.getAnonymousClasses()) {
                if (!cg.isAbstract())
                   writer.append("        " + cg.getJavaName() + ".register();\n");
            }
        }
        writer.append("    }\n");
        writer.append("}\n");
        writer.close();
    }
}
